package com.bawei.base.http

import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.net.Proxy
import java.util.concurrent.TimeUnit

class RetrofitUtils {
    companion object{
        fun getRetrofit():Retrofit{
            val client = OkHttpClient.Builder()
                .readTimeout(5,TimeUnit.MINUTES)
                .writeTimeout(5,TimeUnit.MINUTES)
                .connectTimeout(5,TimeUnit.MINUTES)
            //
                .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                .addInterceptor(TokenInterceptor())
                .retryOnConnectionFailure(true)
                .proxy(Proxy.NO_PROXY)//防止抓包
                .build()

            //
            val retrofit = Retrofit.Builder()
                .baseUrl(Conds.BASE_URL)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .build()

            return retrofit

        }
    }
}